package algorithm.leetcode.I1to100;

import java.util.Arrays;

public class Q66 {

    public int[] plusOne(int[] digits) {
        // 这里执行加1
        int carry = 1;

        int[] res = new int[digits.length + 1];
        for (int i = digits.length-1; i >= 0; i--) {
            int digit = carry + digits[i];
            res[i+1] = digit % 10;
            carry = digit / 10;
        }
        res[0] = carry;
        return carry == 0 ? Arrays.copyOfRange(res, 1, res.length) : Arrays.copyOfRange(res, 0, res.length);
    }

}
